Skip to content

Conversation

@yhabteab
Copy link
Member

This PR introduces an auxiliary DB function for inserting and retrieving the last inserted ID with both the PostreSQL and MySQL drivers. Since the MySQL driver supports/provides LastInsertId() natively, there's nothing special that this function needs to do. On the other hand, PostgreSQL doesn't provide such functionality on its own, so you have to append a special RETURNING id text to the query you want to execute and scan the result into a given dest of your own.

cherry-picked from #18

@yhabteab yhabteab added the enhancement New feature or request label Aug 14, 2024
@yhabteab yhabteab self-assigned this Aug 14, 2024
@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Aug 14, 2024
@yhabteab yhabteab requested review from julianbrost, lippserd and oxzi and removed request for julianbrost and lippserd August 14, 2024 14:40
Copy link
Member

@oxzi oxzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested this PR with Icinga Notifications after replacing util.InsertAndFetchId with this function in a branch based on #127. Thanks and sorry for the delay.

@oxzi oxzi modified the milestones: 0.7.0, 0.6.4 Apr 29, 2025
@oxzi oxzi merged commit 3b2195f into main Apr 29, 2025
14 checks passed
@oxzi oxzi deleted the last-insert-id branch April 29, 2025 13:14
oxzi added a commit to Icinga/icinga-notifications that referenced this pull request Apr 29, 2025
With Icinga/icinga-go-library#64 and
Icinga/icinga-go-library#127 being merged,
the internal/utils package is moved to the IGL and can be removed
here. This is another step to unify our Go codebase.
oxzi added a commit to Icinga/icinga-notifications that referenced this pull request Apr 30, 2025
With Icinga/icinga-go-library#64 and
Icinga/icinga-go-library#127 being merged,
the internal/utils package is moved to the IGL and can be removed
here. This is another step to unify our Go codebase.
oxzi added a commit to Icinga/icinga-notifications that referenced this pull request May 8, 2025
With Icinga/icinga-go-library#64 and
Icinga/icinga-go-library#127 being merged, most
of the internal/utils package is moved to the IGL and can be removed
here. This is another step to unify our Go codebase.
oxzi added a commit to Icinga/icinga-notifications that referenced this pull request Jun 30, 2025
With Icinga/icinga-go-library#64 and
Icinga/icinga-go-library#127 being merged, most
of the internal/utils package is moved to the IGL and can be removed
here. This is another step to unify our Go codebase.
oxzi added a commit that referenced this pull request Oct 9, 2025
With #64 and
#127 being merged, most
of the internal/utils package is moved to the IGL and can be removed
here. This is another step to unify our Go codebase.
oxzi added a commit that referenced this pull request Oct 21, 2025
With #64 and
#127 being merged, most
of the internal/utils package is moved to the IGL and can be removed
here. This is another step to unify our Go codebase.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla/signed CLA is signed by all contributors of a PR enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants